package com.xdwanj.geoquiz.live;

import android.util.Log;

import androidx.lifecycle.ViewModel;

import com.xdwanj.geoquiz.R;
import com.xdwanj.geoquiz.pojo.Question;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class QuizViewModel extends ViewModel {
    private static final String TAG = "QuizViewModel";

    public int currentIndex = 0;
    public boolean isCheater = false;
    List<Question> questionList = new ArrayList<>();

    //构造方法
    public QuizViewModel() {

        questionList.addAll(Arrays.asList(
                new Question(R.string.question_chinese, true),
                new Question(R.string.question_japanese, true),
                new Question(R.string.question_american, false)
        ));

    }

    public boolean getCurrentQuestionAnswer() {
        return questionList.get(currentIndex).isTrue;
    }

    public int getCurrentQuestionText() {
        return questionList.get(currentIndex).questionName;
    }

    public int moveNext() {
        if (currentIndex == questionList.size() - 1) {
            currentIndex = 0;
        } else {
            currentIndex += 1;
        }
        return questionList.get(currentIndex).questionName;
    }

    public int movePre() {
        if (currentIndex == 0) {
            currentIndex = questionList.size() - 1;
        } else {
            currentIndex -= 1;
        }
        return questionList.get(currentIndex).questionName;
    }

    //ViewModel销毁调用
    @Override
    protected void onCleared() {
        super.onCleared();
        Log.d(TAG, "QuizViewModel is destroy");
    }
}
